package com.xsky.logic;

import java.util.List;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.basic.DateConverter;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.xsky.converter.XStreamClobConverter;
import com.xsky.database.dao.impl.BaseEntityDaoImpl;
import com.xsky.operation.vo.Department;
import com.xsky.operation.vo.Office;

public class DepartLogic 
{
	public String genAllDept()
	{
		BaseEntityDaoImpl baseDao = new BaseEntityDaoImpl();
		List deptList = baseDao.findByHql("from Department model");
		String result = "<data>";
		XStream xs = new XStream(new DomDriver());
		String defaultFormat = "yyyy-MM";
		String[] acceptableFormat = {"yyyy-MM"};
		xs.registerConverter(new DateConverter(defaultFormat,acceptableFormat));
		xs.registerConverter(new XStreamClobConverter());
		xs.alias("item", Department.class);
		for (int i =0; i<deptList.size(); i++)
		{
			Department entity = (Department)deptList.get(i);
			result+=xs.toXML(entity);
		}
		result+="</data>";
		return result;
	}
	public String genOfficeByDeptId(String deptId)
	{
		BaseEntityDaoImpl baseDao = new BaseEntityDaoImpl();
		List deptList = baseDao.findByHql("from Office model where model.deptId='"+deptId+"'");
		String result = "<data>";
		XStream xs = new XStream(new DomDriver());
		String defaultFormat = "yyyy-MM";
		String[] acceptableFormat = {"yyyy-MM"};
		xs.registerConverter(new DateConverter(defaultFormat,acceptableFormat));
		xs.registerConverter(new XStreamClobConverter());
		xs.alias("item", Office.class);
		for (int i =0; i<deptList.size(); i++)
		{
			Office entity = (Office)deptList.get(i);
			result+=xs.toXML(entity);
		}
		result+="</data>";
		return result;
	}
}
